<?php
$directory = "data/";

if (isset($_POST['action'])&&!empty($_POST['action']))
{
  $action = $_POST['action'];
  if (strcmp($action, "img.dat")==0)  
  {
    date_default_timezone_set('America/New_York');
    $today = date("Y-m-d");
    $contents = file_get_contents($directory.$today.".dat");
    echo $contents;
    echo ";";
    $contents = file_get_contents($directory.$today.".event");
    echo $contents;
    echo ";";
    $contents = file_get_contents($directory."alert.dat");
    echo $contents;    
  }
  else if (strcmp($action, "img.dat2")==0)
  {
    $files = glob($directory."*.dat");

    foreach ($files as $file)
    {
      if (strcmp($file, $directory."trainingseq.dat")&&strcmp($file, $directory."count.dat")&&strcmp($file, $directory."event.dat")&&strcmp($file, $directory."newevent.dat")&&strcmp($file, $directory."traindata.dat")&&strcmp($file, $directory."userevent.dat")&&strcmp($file, $directory."alert.dat")&&strcmp($file, $directory."newalert.dat"))
      {
        $contents = file_get_contents($file);
        echo $contents;
        echo "\r\n";
      }
    }
    
    echo ";";
    $contents = file_get_contents($directory."event.dat");
    echo $contents;
  }
  else if (strcmp($action, "dates.dat")==0)
  {
    $files = glob($directory."*.dat");
    
    foreach ($files as $file)
    {
      if (strcmp($file, $directory."trainingseq.dat")&&strcmp($file, $directory."count.dat")&&strcmp($file, $directory."event.dat")&&strcmp($file, $directory."newevent.dat")&&strcmp($file, $directory."traindata.dat")&&strcmp($file, $directory."userevent.dat")&&strcmp($file, $directory."alert.dat")&&strcmp($file, $directory."newalert.dat"))
      {
        echo $file;
        echo "\r\n";
      }      
    }
  }
  else if (strcmp($action, "count.dat")==0)
  {
    $contents = file_get_contents($directory."count.dat");
    echo $contents;
  }
  else if (strcmp($action, "newevent.dat")==0)
  {
    $contents = file_get_contents($directory."newevent.dat");
    echo $contents;
  }
  else if (strcmp($action, "newalert.dat")==0)
  {
    $contents = file_get_contents($directory."newalert.dat");
    echo $contents;
  }  
  else
  {
    $contents = file_get_contents($action);
    echo $contents;    
  }
}
?>